//
//  Status.swift
//  sina
//
//  Created by DXapple on 15/11/16.
//  Copyright © 2015年 sqlite. All rights reserved.
//

import UIKit

class Status: NSObject {
    
    var created_at:	String?
    //微博id
    var id: Int = 0
    //微博信息内容
    var text: String?
    //微博来源
    var source: String?
    //配图视图数组
    var pic_urls: [[String : String]]?
    var imageURLs: [NSURL]? {
        guard let urls = pic_urls else{
        
        return nil
        }
        var tempArray = [NSURL]()
        for item in urls {
            let url = NSURL(string: item["thumbnail_pic"]!)
            tempArray.append(url!)
        
        }
        return tempArray
    
    }
    //定义计算属性同时代表原创微博和转发微博的图品数组
    var pictureURLs: [NSURL]? {
    //如果转发微博不为空
        if  retweeted_status != nil {
            return retweeted_status?.imageURLs
        }
        return imageURLs
    }
    
    
    
    //赚翻微博原创字段
    var retweeted_status: Status?
    
    
    
    //user
    var user: User?
    init(dict: [String : AnyObject]) {
        super.init()
        self.setValuesForKeysWithDictionary(dict)
    }
    
    override func setValue(value: AnyObject?, forKey key: String) {
        
        if key ==  "user"
        {
            if let dict = value as? [String :AnyObject ]{
            user = User(dict: dict)
            }
            return
        
        }
        if key ==  "retweeted_status"
        {
            if let dict = value as? [String :AnyObject ]{
                retweeted_status = Status(dict: dict)
            }
            return
            
        }

        
        super.setValue(value, forKey: key)
        
    }
    
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
        
    }
    
}












